<template>
  <div class="app-container">
    <el-row>
      <el-form :model="form">
        <el-form-item label="自动冻结开门权限">
          <el-switch v-model="form.autoFrozenState" active-value="1" inactive-value="2"
                     @change="handleAutoFrozenChange"
          ></el-switch>
          <div class="tips">
            每天0点统一处理，超过退房日期未进行完成退房的房间，智能门锁自动冻结开门权限，完成退房/续租后自动解除冻结
          </div>
        </el-form-item>
        <!-- 保存 -->
        <!--        <el-button type="primary" @click="handleSubmit">保存</el-button>-->
      </el-form>
    </el-row>

  </div>
</template>

<script>
import { debounce } from '@/utils'
import { getLockSettingStatus, updateAutoFreezeStatus } from '@/api/smartLock/setting'

export default {
  name: 'index',
  data() {
    return {
      form: {
        lockSettingId: '',
        autoFrozenState: '1'
      }
    }
  },
  created() {
    this.getLockInfo()
  },
  methods: {
    getLockInfo() {
      getLockSettingStatus().then(response => {
        this.form = response.rows[0]
      })
    },
    // 提交
    handleAutoFrozenChange: debounce(function() {
      // this.updateAutoFreezeStatus()
      updateAutoFreezeStatus(this.form).then(response => {
        this.$message.success('保存成功')
        this.getLockInfo()
      }).catch(error => {
        this.getLockInfo()
      })
    }, 500, false),
  }
}
</script>

<style scoped lang="scss">
.tips {
  font-size: 12px;
  color: #999;
  margin-top: 5px;
}
</style>
